package model.blocks;

import model.baseElements.BaseBlock;
import model.pages.MainPage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;
import ru.yandex.qatools.htmlelements.annotations.Block;
import ru.yandex.qatools.htmlelements.element.HtmlElement;

@Block(@FindBy(id="search_form"))
public class SearchBlock extends BaseBlock {

    @FindBy(id = "location")
    WebElement whereToGo;
    @FindBy(id = "checkin")
    WebElement checkIn;
    @FindBy(id = "checkout")
    WebElement checkOut;
    @FindBy(id = "guests")
    WebElement guests;

    public SearchBlock(WebDriver driver) {
        super(driver);
    }

    public SearchBlock setWhereToGo(String whereToGo) {
        this.whereToGo.sendKeys(whereToGo);
        return this;
    }

    public SearchBlock setCheckIn(String checkIn) {
        this.checkIn.clear();
        this.checkIn.sendKeys(checkIn);
        return this;
    }

    public SearchBlock setCheckOut(String checkOut) {
        this.checkOut.clear();
        this.checkOut.sendKeys(checkOut);
        return this;
    }

    public SearchBlock setGuests(String guests) {
        new Select(this.guests).selectByVisibleText(guests);
        return this;
    }
}
